package com.hibernate.hrm.service.login;

import com.hibernate.hrm.entity.dto.login.UserInfoDTO;
import com.hibernate.hrm.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class AuthService {

    @Transactional(readOnly = true)
    public UserInfoDTO getUserInfo(User user) {
        return UserInfoDTO.builder()
                .userId(user.getUserId())
                .username(user.getUsername())
                .realName(user.getRealName())
                .roleName(user.getRoleId().getRoleName())
                .departmentName(user.getDepartmentID() != null ?
                        user.getDepartmentID().getDepartmentName() : null)
                .positionName(user.getJobPositionID() != null ?
                        user.getJobPositionID().getPositionName() : null)
                .build();
    }
}
